package com.wwq.websocket.demo.websocketdemo.controller;

import com.wwq.websocket.demo.websocketdemo.viewmodel.RequestMessage;
import com.wwq.websocket.demo.websocketdemo.viewmodel.ResponseMessage;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class WsController {

    /**
     * @SendTo注解表示当服务器有消息需要推送的时候，会对订阅了@SendTo中路径的浏览器发送消息
     * @param requestMessage
     * @return
     */
    @MessageMapping("/welcome")
    @SendTo("/topic/getResponse")
    public ResponseMessage say(RequestMessage requestMessage) {
        System.out.println(requestMessage.getName());
        return new ResponseMessage("welcome " + requestMessage.getName());
    }

    @GetMapping("wsPage")
    public String wsPage() {
        return "ws";
    }



}
